package com.lx.router;

import com.lx.handler.TimeHandler;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RouterFunctions.route;

/**
 * 配置请求路径
 *
 * @author 段誉
 * @create 2019-05-15 13:17
 */
@Configuration
public class TimeRouter {

  @Bean
  public RouterFunction<ServerResponse> timerRouter(TimeHandler timeHandler) {
    //使用建造者模式添加
    //GET中的两种写法都可以
    return route()
            .GET("/time", req -> timeHandler.getTime(req))
            .GET("/date", timeHandler::getDate)
            .GET("/times", timeHandler::sendTimePerSec)
            .build();
    // 正常一个一个链接添加
//    return route(GET("/time"), timeHandler::getTime)
//            .andRoute(GET("/data"), timeHandler::getDate);
  }
}
